<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-08-15 16:45:26
 * @LastEditors: 李小晴 2689279066@qq.com
 * @LastEditTime: 2023-10-29 11:29:57
 * @FilePath: \grazlink20\uc_sys\src\views\Asset\Pasture\components\Assets.vue
 * Copyright (c) 2022 by 李天惊 uf_lee@163.com, All Rights Reserved. 
 * 单个牧场-打标资产
-->
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { Search } from '@/components/Search'
import { TableLxq } from '@/components/Lxq'
import { useTable } from '@/hooks/web/useTableTest'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { spEnclosureLogOrderDetailedListApi } from '@/api/fa/enclosure'
let registers = ref()

const props = defineProps({
  id: {
    type: Number,
    default: () => null
  }
})
const getListAsset = async (val) => {
  val.enclosure_log_id = props.id
  return spEnclosureLogOrderDetailedListApi(val)
}
const { register, tableObject, methods } = useTable<
  {
    total: number
    list: any[]
  },
  any
>({
  getListApi: getListAsset,
  response: {
    data: 'data',
    count: 'count'
  }
})
const { getList, setSearchParams } = methods

registers.value = register

const crudSchemas = reactive<CrudSchema[]>([
  {
    field: 'pasture_org_name',
    label: '牧场名称',
    width: 220,
    search: {
      show: true
    }
  },
  {
    field: 'asset_code',
    label: '注射编号',
    width: 200,
    search: {
      show: true
    }
  },
  {
    field: 'asset_code_2',
    label: '项圈编号',
    width: 200,
    search: {
      show: true
    }
  },
  {
    field: 'earcon_code',
    label: '耳标编号',
    width: 200,
    search: {
      show: true
    }
  },
  {
    field: 'out_enclosure_id',
    label: '初始栏位',
    width: 220,
    search: {
      show: true
    }
  },
  {
    field: 'in_enclosure_id',
    label: '目标栏位',
    width: 220,
    search: {
      show: true
    }
  },
  {
    field: 'create_time',
    label: '创建时间',
    width: 170,
    form: {
      show: true,
      component: 'DatePicker',
      componentProps: {
        disabled: true,
        type: 'datetime',
        valueFormat: 'YYYY-MM-DD HH:mm:ss'
      }
    },
    search: {
      show: true,
      component: 'DatePicker',
      componentProps: {
        'is-range': true,
        'unlink-panels': true,
        rangeSeparator: 'To',
        type: 'daterange',
        valueFormat: 'YYYY-MM-DD HH:mm:ss'
      }
    }
  }
])
defineExpose({})

const init = async () => {
  // 列表查询
  await getList()
}

init()

const { allSchemas } = useCrudSchemas(crudSchemas)
</script>

<template>
  <div>
    <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
    <div class="mb-10px"> </div>
    <TableLxq
      v-model:pageSize="tableObject.pageSize"
      v-model:currentPage="tableObject.currentPage"
      :columns="allSchemas.tableColumns"
      :data="tableObject.tableList"
      :loading="tableObject.loading"
      :border="true"
      :pagination="{
        total: tableObject.count
      }"
      @register="register"
      :selection="false"
      highlight-current-row
    />
  </div>
</template>
<style lang="less" scoped></style>
